<!doctype html>
<html>

    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
        <title>APICloud APP</title>
        <link rel="stylesheet" type="text/css" href="../css/api.css" />
        <style>
            html,
            body {
                height: 100%;
                background: #f0f0f0;
            }
            
            .h20 {
                height: 20px;
            }
            
            .title {
                background-color: rgb(138, 136, 129);
                height: 44px;
                line-height: 44px;
                padding-left: 10px;
                color: #fff;
                font-size: 14px;
                border-bottom: solid rgb(96, 96, 96) 1px;
            }
            
            .item {
                background-color: #fff;
                height: 44px;
                line-height: 44px;
                padding-left: 10px;
                color: #000;
                font-size: 14px;
                border-bottom: solid rgb(215, 215, 215) 1px;
            }
            
            .item>img {
                float: right;
                padding-top: 10px;
                padding-right: 10px;
                height: 25px;
            }
        </style>
    </head>

    <body>
        <div class="h20"></div>
        <div class="item" tapmode onclick="fnChange('user')">
            <span>用户消息</span>
            <img id="user" src="../image/switch_on.png">
        </div>
        <div class="h20"></div>
        <div class="item" tapmode onclick="fnChange('system')">
            <span>系统消息</span>
            <img id="system" src="../image/switch_on.png">
        </div>
        <div class="h20"></div>
        <div class="item" tapmode onclick="fnChange('broadcast')">
            <span>广播消息</span>
            <img id="broadcast" src="../image/switch_on.png">
        </div>
    </body>
    <script type="text/javascript" src="../script/api.js"></script>
    <script type="text/javascript">
        apiready = function() {
            fnInit();

            userFlag = !userFlag;
            fnChange('user');

            systemFlag = !systemFlag;
            fnChange('system');

            broadcastFlag = !broadcastFlag;
            fnChange('broadcast');
        };

        var user, system, broadcast;
        var userFlag, systemFlag, broadcastFlag;

        function fnInit() {
            user = $api.byId('user');
            system = $api.byId('system');
            broadcast = $api.byId('broadcast');

            userFlag = $api.getStorage('user_disabled') || false;
            systemFlag = $api.getStorage('system_disabled') || false;
            broadcastFlag = $api.getStorage('broadcast_disabled') || false;
        };

        function fnChange(key) {
            window[key + 'Flag'] = !window[key + 'Flag'];
            $api.setStorage(key + '_disabled', window[key + 'Flag']);

            var onoff = window[key + 'Flag'] ? 'on' : 'off';
            window[key].src = '../image/switch_' + onoff + '.png';
        };
    </script>
    </html
